package com.hqyj.system.controller;

import com.hqyj.system.model.Finance;
import frame.controller.BaseController;
import frame.pageUtil.PagedResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.sql.ClientInfoStatus;
import java.util.List;

@Controller
@RequestMapping("/financeController")
public class FinanceController extends BaseController {
    @RequestMapping("/listpage.do")
    public ModelAndView listpage(@RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                                 @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize){

        ModelAndView mv = new ModelAndView();
        int incomeSum=0;
        int expenditureSum=0;
        //获取分页数据
        PagedResult<Finance> pageResult= financeService.getAllFinancePageByPage(pageNumber,pageSize);
        //获取全部数据
        List<Finance> finances = financeService.queryAllFinance();
        //遍历所有数据，计算总支出和总收入

        for (Finance finance : finances) {
            if("收入".equals(finance.getBill())){
                incomeSum+=finance.getFinancePrice();
            }else {
                expenditureSum+=finance.getFinancePrice();
            }
        }
        mv.addObject("incomeSum",incomeSum);
        mv.addObject("expenditureSum",expenditureSum);
        mv.addObject("pageResult",pageResult);
        mv.setViewName("view/system/finance/financePagelist");
        return mv;
    }
}
